<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0" />
        <title>5. 5种基本类型</title>
    </head>
    <body>
        <script>
            // 1. Number类型
            // 1.1 特殊数字 Infinity、-Infinity、NaN
            var aa = Infinity;
            console.log('aa -> type ' + typeof aa + '\tvalue ' + aa);
            var bb = -Infinity;
            console.log('bb -> type ' + typeof bb + '\tvalue ' + bb);
            var cc = NaN;
            console.log('cc -> type ' + typeof cc + '\tvalue ' + cc);
            // 1.2 Int、Float
            var a = 18;
            console.log('a -> type ' + typeof a + '\tvalue ' + a);
            var b = 18.8;
            console.log('b -> type ' + typeof b + '\tvalue ' + b);
            // 1.3 类型转化  parseInt、parseFloat、Number、隐式转化（- * /）
            var a1 = parseInt('123');
            console.log('a1 -> type ' + typeof a1 + '\tvalue ' + a1);
            var a2 = parseInt('12px');   // 会自动去掉后面的字符串
            console.log('a2 -> type ' + typeof a2 + '\tvalue ' + a2);
            var a3 = parseFloat('456');
            console.log('a3 -> type ' + typeof a3 + '\tvalue ' + a3);
            var a4 = parseFloat('123.34');
            console.log('a4 -> type ' + typeof a4 + '\tvalue ' + a4);
            var a5 = parseInt('adf123.34');     // NaN
            console.log('a5 -> type ' + typeof a5 + '\tvalue ' + a5);
            var a6 = parseFloat('adf123.34'); 
            console.log('a6 -> type ' + typeof a6 + '\tvalue ' + a6);
            var a7 = Number('123')
            console.log('a7 -> type ' + typeof a7 + '\tvalue ' + a7);
            var a8 = Number('11233.213')
            console.log('a8 -> type ' + typeof a8 + '\tvalue ' + a8);

            // 2. String 类型
            var str1 = "liming"
            console.log(typeof str1);
            var str2 = a.toString()
            console.log(typeof str2);
            var str3 = String(123.123);
            console.log('str3 -> type ' + typeof str3 + '\tvalue ' + str3);
            var str4 = '' + 'fsff';
            console.log('str4 -> type ' + typeof str4 + '\tvalue ' + str4);
            
            // 3. boolean
            var b1 = false;
            console.log('b1 -> type ' + typeof b1 + '\tvalue ' + b1);
            var b2 = Boolean('fs');
            console.log(Boolean(null)); // false
            console.log(Boolean(NaN));  // false
            console.log(Boolean(false));// false
            console.log(Boolean(0));    // false
            console.log(Boolean(''));   // false
            console.log(Boolean(Infinity)); // true
            
            // 4. undefined
            var u1;
            console.log(typeof u1);
            var u2 = undefined;
            console.log(typeof u2);
            
            // 5. null
            var n1 = null;
            console.log(typeof n1);
            
        </script>
    </body>
</html>